home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11972 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: tank.news.pipex.net!pipex!iol!usenet
  2. From: David Byrden <goyra@iol.ie>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Class constructor usage within another class constructor problem!
  5. Date: 17 Mar 1996 13:08:46 GMT
  6. Organization: Ireland On-Line
  7. Message-ID: <4ih2su$t30@nuacht.iol.ie>
  8. References: <DoEv3x.IDL@latcs1.lat.oz.au>
  9. NNTP-Posting-Host: dialup-397.dublin.iol.ie
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22KIT (Windows; I; 16bit)
  14.  
  15.  
  16. boylesgj@lion.cs.latrobe.edu.au (Gregary J Boyles) wrote:
  17.  
  18. > Address::Address(int ANumber,const char *AStreet,const char *ACity,int AZip)
  19. > {
  20. >      Number=ANumber;
  21. >      // *******************************************************************
  22. >      // The next two lines create objects of class String. Do these objects
  23. >      // get placed into the Street and City members of class Address, i.e.
  24. >      // are these lines equivelent to Address.Street=AStreet etc or have I
  25. >      // got it wrong?
  26. >      // *******************************************************************
  27. >      String Street(AStreet);
  28. >      String City(ACity);
  29.  
  30.  
  31.    You've got it wrong. You have created local objects in the function 
  32. block. What you want to do here, is read a C++ book about Constructor 
  33. Initialiser Lists and say
  34.  
  35.  Address::Address(int ANumber,const char *AStreet,
  36.     const char *ACity,int AZip)
  37.  : Street(AStreet), City(ACity)
  38. {
  39.  
  40.  
  41.  
  42.  
  43.  
  44. > Address::Address(Address& AnAddress)
  45. > {
  46. >      Number=AnAddress.Number;
  47. >      // **********************************************************************
  48. >      // Can't pass AnAddress.Street by reference i.e. AnAddress.Street & as 
  49. >      // it generates a compile error. Why?
  50. >      // **********************************************************************
  51. >      String Street(AnAddress.Street);
  52.  
  53.  
  54.  
  55.    You DID pass it by reference. At the point where you evaluate the 
  56. parameter, there is no syntactical difference between passing a value and 
  57. a reference. Once again, you need to do some study. Experimenting with 
  58. things you don't understand is a comparatively slow way to learn C++.
  59.  
  60.  
  61.                                     David    :-)
  62.  
  63.  
  64.